package com.masterrabbit.mcslf.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.masterrabbit.mcslf.mapper.ServicePackageMapper;
import com.masterrabbit.mcslf.pojo.Packages;
import com.masterrabbit.mcslf.pojo.ServicePackage;
import com.masterrabbit.mcslf.service.PackagesService;
import com.masterrabbit.mcslf.mapper.PackagesMapper;
import com.masterrabbit.mcslf.service.ServicePackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author hasee
* @description 针对表【packages】的数据库操作Service实现
* @createDate 2025-03-22 15:00:04
*/
@Service
public class PackagesServiceImpl extends ServiceImpl<PackagesMapper, Packages>
    implements PackagesService{
    @Autowired
     PackagesMapper packagesMapper;
    @Autowired
    ServicePackageMapper servicePackageMapper;
    @Autowired
    ServicePackageService servicePackageService;
    @Override
    @Transactional
    public void add(Packages packages, List<Integer> ids) {

        packagesMapper.insert(packages);
        List<ServicePackage> collect = ids.stream().map(item -> {
            ServicePackage servicePackage = new ServicePackage();
            servicePackage.setServiceId(item);
            servicePackage.setPackageId(packages.getPackageId());
            return servicePackage;
        }).collect(Collectors.toList());
        servicePackageService.saveBatch(collect);
    }
}




